package drds.server.net.packet.auth;

import java.io.IOException;
import java.io.OutputStream;

import drds.server.net.packet.BytesHolder;
import drds.server.net.packet.Packet;

/**
 * From client to server during initial handshake.
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class AuthRequestPacket extends Packet {
	public String database;
	public String userName;
	public byte[] password;

	public void read(byte[] bytes) {
		BytesHolder bytesHolder = new BytesHolder(bytes);
		packetLength = bytesHolder.readInt3();
		packetId = bytesHolder.read();
		//
		userName = bytesHolder.readStringWithNull();
		password = bytesHolder.readBytesWithLength();
		database = bytesHolder.readStringWithNull();
	}

	public void write(OutputStream outputStream) throws IOException {
		throw new RuntimeException();
	}

	@Override
	public int computePacketSize() {
		int size = 4;//
		size += database.length();
		size += userName.length();
		size += password.length;
		return size;
	}

}